﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KL.Store.Core.Domain;
using TN.Data;

namespace KL.Store.Data
{
    public class dbVoucher
    {
        #region Insert

        public static long Insert(int UserId, short TypeId, bool Enabled, bool Used, decimal PriceLimit, DateTime ValidDate, int CreateUser, decimal Payment, bool Approved, string Comment, bool Denied, string Info, int PosId, short InstallmentNo, int BankId, DateTime Time)
        {
            return (long)SqlHelper.ExecuteScalar(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Insert", new object[] { UserId, TypeId, Enabled, Used, PriceLimit, ValidDate, CreateUser, Payment, Approved, Comment, Denied, Info, PosId, InstallmentNo, BankId, Time });

        }

        #endregion

        #region Update

        public static void Update(int UserId, long VoucherId, bool Enabled, bool Used, int UpdateUser, int OrderId, bool Approved, string Comment)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Update", new object[] { UserId, VoucherId, Enabled, Used, UpdateUser, OrderId, Approved, Comment });
        }

        #endregion

        #region UpdatePaymentNotification

        public static void UpdatePaymentNotification(int UserId, long VoucherId, bool PaymentNotification)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Payment_Notification", new object[] { UserId, VoucherId, PaymentNotification });
        }

        #endregion

        #region Delete

        public static void Delete(int UserId, long VoucherId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Delete", new object[] { UserId, VoucherId });
        }

        #endregion

        #region Get

        public static Voucher Get(int UserId, long VoucherId)
        {
            IList<Voucher> objectList = new List<Voucher>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Get", objectList, new object[] { UserId, VoucherId });
            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetByOrderId

        public static OrderCompletedVoucher GetByOrderId(int UserId, int OrderId)
        {
            IList<OrderCompletedVoucher> objectList = new List<OrderCompletedVoucher>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Voucher_Get_By_OrderId", objectList, new object[] { UserId, OrderId });
            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetList

        public static IList<Voucher> GetList(int UserId)
        {
            IList<Voucher> objectList = new List<Voucher>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Voucher_List", objectList, new object[] { UserId });

            return objectList;
        }

        #endregion

        #region GetOrderPayments

        public static IList<Voucher> GetOrderPayments(int UserId, int OrderId)
        {
            IList<Voucher> objectList = new List<Voucher>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Voucher_GetOrderPayments", objectList, new object[] { UserId, OrderId });

            return objectList;
        }

        #endregion
    }
}
